package com.talkology.pilot.teacher.controller;

import com.talkology.pilot.database.model.TeachersTimeMgt;
import com.talkology.pilot.teacher.service.ITeachersTimeMgtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/teacherTime")
public class TeachersTimeMgtController {

    @Autowired
    private ITeachersTimeMgtService service;


    @RequestMapping(value = "/all", method= RequestMethod.GET)
    @ResponseBody
    public List<TeachersTimeMgt> getTeacherByFilter(@RequestParam(value = "name", required = false) String name,
                                                    @RequestParam(value = "type", required = false) String type) {

        return service.getAllByFilter(name, type);
    }

    @RequestMapping(value = "/add", method= RequestMethod.PUT)
    @ResponseBody
    public void addTeacherInfo(@RequestBody TeachersTimeMgt timeMgt) {
        service.add(timeMgt);
    }

    @RequestMapping(value = "/update", method= RequestMethod.PUT)
    @ResponseBody
    public void updateTeacherInfo(@RequestBody TeachersTimeMgt timeMgt) {
        service.edit(timeMgt);
    }

    @RequestMapping(value = "/delete", method= RequestMethod.DELETE)
    @ResponseBody
    public void deleteTeacherInfo(@RequestParam(value = "index", required = false) Long index) {
        service.delete(index);
    }

}
